/**
 * @file       TestCommand.cpp
 * @brief      
 * @author     LiuJkun
 * @version    1.0.0
 */

/*********************************************************************
 *  LiuJikun   10/03/09      Initial Version
 *********************************************************************/
#include	<stdint.h>
#include	<stdio.h>
#include	<string.h>
#include	<arpa/inet.h>

#include	<network/EpollChannel.h>
#include	<network/Socket.h>
#include	<network/Epollor.h>

#include	"TestCommand.h"

/**
 * @brief  constructor for class TestCommand
 */
//--------------------------------------------------------------------------------------
TestCommand::TestCommand ( const MyUtil::PacketPtr &packet) : _m_packet(packet)
{
}

/**
 * @brief 
 * @return
 */
void  TestCommand::handle ( void )
{
    MyUtil::PacketPtr packet = new MyUtil::Packet;
//    const char *ptr = _m_packet->data.c_str();
//    int32_t len = ntohl( *(int32_t*) ptr );
//    int32_t type = ntohl( *(int32_t*) (ptr+4) );
//    int32_t subType = ntohl( *(int32_t*) (ptr+8) );
//    int32_t id = ntohl( *(int32_t*) (ptr + 12) );
//
    char response[1000];
    char html_content[]="<html><body>hello, this is ice server</body></html>";
    memset(response, 0, 1000);
    snprintf(response
            , 1000
            , "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nContent-Length: %d\r\n\r\n%s"
            , strlen(html_content)
            , html_content);

    packet->fd = this->_m_packet->fd;
    packet->data.append( response, strlen(response) );
    MyUtil::PacketedChannelQueue::instance().putPacket( packet );
    MyUtil::EpollChannelPtr channel = MyUtil::Epollor::instance().findChannel(packet->fd);
    MyUtil::Epollor::instance().deregisterChannel(channel);
}		

